package com.shardingjdbc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shardingjdbc.entity.Book;
import com.shardingjdbc.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhanglei01
 * @date 2020/9/21 17:17
 */
@RestController
@Api(tags = {"书籍管理接口"},description = "书籍管理接口")
public class BookController {

    @Autowired
    private BookService bookService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "查询书籍列表",notes = "查询书籍列表")
    public List<Book> list(){
        return bookService.getBookList();
    }

    @ApiOperation(value = "分页查询书籍列表",notes = "分页查询书籍列表")
    @RequestMapping(value = "/listpage", method = RequestMethod.GET)
    public IPage<Book> listpage(){
        return bookService.getBookListPage(1, 2);
    }

    @ApiOperation(value = "新增书籍",notes = "新增书籍")
    @ApiImplicitParam(name = "saveItem",value = "参数数据",required = true,dataType = "Book")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public Boolean saveItem(@RequestBody Book book){
        return bookService.save(book);
    }

}
